package com.chocus.core.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.chocus.core.bean.product.Sku;
import com.chocus.core.service.product.SkuService;

@Controller
@RequestMapping("/sku/")
public class SkuController {

	@Autowired
	private SkuService skuService;

	/**
	 * 列表
	 * 
	 * @param productId
	 * @param model
	 * @return
	 */
	@RequestMapping("list.do")
	public String list(Long productId, Model model) {
		List<Sku> skuList = skuService.getSkuList(productId);
		model.addAttribute("skuList", skuList);
		return "sku/list";
	}

	/**
	 * 修改
	 * 
	 * @param productId
	 * @param model
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("update.do")
	public void update(Sku sku, HttpServletResponse response) throws IOException {
		skuService.updateSku(sku);
		response.setContentType("application/json;charset=utf-8");
		JSONObject jb = new JSONObject();
		jb.put("msg", "保存成功!");
		response.getWriter().write(jb.toString());
	}
}
